package com.pine.dbant.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pine.dbant.core.entity.Directory;
import com.pine.dbant.core.model.vo.DirTreeVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DirectoryMapper  extends BaseMapper<Directory> {


    /**
     * 获取目录和连接组成的树形数据
     * @return
     */
    @Select("<script>" +
            "SELECT a.id,a.parent_id,a.`name` ,'DIR' type FROM  dba_directory a\n" +
            "UNION\n" +
            "select a.res_id parent_id,b.id id,b.conn_name name,'CONN' type  FROM dba_relation a,dba_connection b where a.target_id=b.id\n" +
            "UNION \n" +
            "SELECT a.id,\"\" parent_id,a.conn_name name,'CONN' type FROM dba_connection a where not EXISTS (SELECT b.* FROM dba_relation b where a.id=b.target_id)" +
            "</script>")
    List<DirTreeVO> getConnTree();

    /**
     * 获取目录和连接组成的树形数据
     * @return
     */
    @Select("<script>" +
            "SELECT a.id,a.parent_id,a.`name` ,'DIR' type FROM  dba_directory a\n" +
            "</script>")
    List<DirTreeVO> getDirTree();
}
